#pragma once
#include "poly_container.h"

namespace congruent_packing
{

poly_container_t::poly_container_t()
{
}

void poly_container_t::clamp_point(PointF & v)
{
	size_t size = poly.size();

	for(size_t i = 0; i < size; ++i)
	{
		double dx = poly[i].x - poly[( i + 1 ) % size].x;
		double dy = poly[i].y - poly[( i + 1 ) % size].y;
		double nx = -dy;
		double ny = dx;
		double dot = nx * v.x + ny * v.y;
		if(dot < 0.0)	// outside
		{
			v.x = poly[i].x;
			v.y = poly[i].y;
			return;
		}
	}
}

void poly_container_t::add_point(double x, double y)
{
	PointF pnt;
	pnt.x = x;
	pnt.y = y;
	poly.push_back(pnt);
}

}